
<html>
<head>

    <link rel="stylesheet" href="/layui/css/layui.css">

    <style>
        .center{
            display: flex;
            width: fit-content;
            margin: auto;
        }
    </style>
</head>
<body>


<form class="layui-form" action="" onsubmit="submit1();return false;" style="margin-right: 80px;margin-top: 30px;">

    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" required  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input" value="{$data.name}">
        </div>
    </div>

    <input type="hidden" name="id" id="id" value="{$data.id}">

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">提交</button>
        </div>
    </div>
</form>


<script src="/js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script src="/layui/layui.js"></script>
<script>

   layui.use('form', function () {
       var form = layui.form;
       form.render()
   });

    function submit1() {

        layui.use('layer', function () {
            var name = $('#name').val();
            var id = $('#id').val();


            $.post('/ops/category/add', {name: name, id: id}, function (res) {
                var res = JSON.parse(res);
                if(res.errno == 0){
                    layer.msg('操作成功');
                    parent.location.reload();
                }else{
                    layer.msg(res.msg, function (e) {

                    })
                }

                return false;
            });

            return false;
        })

    }

</script>

</body>

</html>


